<?php
/**
 * 对象结构
 * Class ObjectStructure
 */
class ObjectStructure
{
    public $elements = [];

    /**
     * 添加
     * @param ElementPerson $elementPerson
     */
    public function add(ElementPerson $elementPerson)
    {
        $this->elements[] = $elementPerson;
    }

    /**
     * 移除
     * @param ElementPerson $elementPerson
     */
    public function remove(ElementPerson $elementPerson)
    {
        foreach ($this->elements as $key => $value) {
            if ($value == $elementPerson) {
                unset($this->elements[$key]);
            }
        }
    }

    /**
     * 查看显示
     * @param VisitorState $visitorState
     */
    public function display(VisitorState $visitorState)
    {
        foreach ($this->elements as $element) {
            $element->accept($visitorState);
        }
    }
}



